<?php

use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\File;

class CmeTableSeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $filePath = 'json/cme-05-04';
        $data = json_decode(File::get(storage_path($filePath)), true);
        $columnNames = array_map(function ($value) {
            return snake_case($value);
        }, $data['dataset']['column_names']);
        $cmeData = [];

        foreach ($data['dataset']['data'] as $datum) {
            $cmeData[] = array_combine($columnNames, $datum);
        }

        \App\CmeData::insert($cmeData);

    }
}
